package com.alex.ip.holder.server.config;

import cn.hutool.core.thread.ThreadUtil;
import com.alex.ip.holder.server.service.ClientService;
import com.alex.ip.holder.server.service.impl.DefaultInMemoryClientService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置類
 *
 * @author Alex.Liu
 * @date: 2025-02-18 15:51
 * @since 1.0.0
 */
@Configuration
public class HolderConfig {

    @Bean
    @ConditionalOnMissingBean(ClientService.class)
    ClientService serverService() {
        return new DefaultInMemoryClientService();
    }

    @Bean
    @ConditionalOnMissingBean(ScheduledExecutorService.class)
    ScheduledExecutorService scheduledExecutorService() {
        ThreadFactory factory = ThreadUtil.createThreadFactory("alex-scheduled-thread-pool-");
        return Executors.newScheduledThreadPool(10, factory);
    }

}
